﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WCFService;
using Database;

namespace WebForum
{
    public partial class SiteMaster : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Label3.ForeColor = System.Drawing.ColorTranslator.FromHtml("#000000");
            if (Session["UserName"] != null)
                Label3.Text = "Logged in as : " + (string)Session["UserName"];
            else
                Label3.Text = "Guest";
            Session["Forum"] = 114;//CHANGE forum here
        }

        protected void click1(object sender, EventArgs e)
        {
            Response.Redirect("http://localhost:6765/ForumPages/ForumPage.aspx/?ForumID=114");//CHANGE forum here
        }

        protected void Button2_Click(object sender, EventArgs e)
        {

            if (Button2.Text == "Logout")
            {
                Session["UserName"] = null;
                Session["Password"] = null;
                Button2.Text = "Login";
                Label3.Text = "Guest";
            }
            else
            {
                AppDomain.CurrentDomain.SetData("SQLServerCompactEditionUnderWebHosting", true);
                LogicForumImp forumManager = new LogicForumImp();
                bool isLogged = forumManager.webLogin((int)Session["Forum"], TextBox2.Text, TextBox1.Text);
                if (isLogged)
                {
                    Session["UserName"] = TextBox2.Text;
                    Session["Password"] = TextBox1.Text;
                    Label3.Text = "Logged in as : " + (string)Session["UserName"];
                    Button2.Text = "Logout";
                }
                else
                {
                    Label3.ForeColor = System.Drawing.ColorTranslator.FromHtml("#ff0000");
                    Label3.Text = "Wrong Username or Password!";
                }
            }

        }
    }
}
